package cn.service.impl;

import cn.dao.KindDao;
import cn.entity.Kind;
import cn.service.KindService;
import cn.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("kindService")
@Scope("prototype")
public class KindServiceImpl implements KindService{
	@Autowired
	KindDao kindDao;
	public KindDao getKindDao() {
		return kindDao;
	}

	public void setKindDao(KindDao kindDao) {
		this.kindDao = kindDao;
	}
	@Override
	public int deleteByPrimaryKey(Object id) {
		return kindDao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Kind record) {
		return kindDao.insert(record);
	}

	@Override
	public Kind selectByPrimaryKey(Object id) {
		return kindDao.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKey(Kind record) {
		return kindDao.updateByPrimaryKey(record);
	}

	@Override
	public List<Kind> find(String name, PageBean pageBean) {
		List<Kind> list=new ArrayList<Kind>();
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("name", name);
		if(pageBean!=null){
			params.put("begin", (pageBean.getPageNo()-1)*pageBean.getPageSize());
			params.put("pageSize", pageBean.getPageSize());
		}
		return kindDao.find(params);
	}

	@Override
	public int getCount(String name) {
		int n=0;
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("name", name);
		return kindDao.getCount(params);
	}
	
}
